package com.ewili.x.special.service.data.impl;

import com.ewili.framework.utils.ExceptionUtils;
import com.ewili.x.special.service.data.inter.BkInfoService;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class BkInfoServiceImpl implements BkInfoService {


    @Override
    public void spideHYInfo() {

        Connection connection = Jsoup.connect("http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?cmd=C._BKHY&type=ct&st=(BalFlowMain)&sr=-1&p=1&ps=1000&js=var%20rcJtwmRD={pages:(pc),data:[(x)]}&token=894050c76af8597a853f5b408b759f5d&sty=DCFFITABK&rt=52154817");
        connection.maxBodySize(0);

        try {
            String content = connection.get().body().text();

            String pattern = "(1,BK)(\\d+),([\\u4E00-\\u9FA5]+),";
            Pattern r = Pattern.compile(pattern);
            Matcher m = r.matcher(content);
            while (m.find()) {
                System.out.print(m.group(2) + "+++++++++" + m.group(3));
                System.out.println("");
            }
        } catch (IOException e) {
            ExceptionUtils.propagate(e);
        }
    }
}
